package com.osc.exam.service.impl;

import com.osc.exam.dao.ProgressDao;
import com.osc.exam.dao.StudentDao;
import com.osc.exam.entity.domain.Progress;
import com.osc.exam.service.ProgressScaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProgressScaleServiceImpl implements ProgressScaleService {

    @Autowired
    private ProgressDao progressDao;
    @Autowired
    private StudentDao studentDao;

    /**
     * 人数及比例信息
     * @return
     */
    @Override
    public Map<String, Object> getInterDate() {
        Map<String,Object> data = new HashMap<>();
        int first = progressDao.queryInterNum(1);
        int second = progressDao.queryInterNum(2);
        int third = progressDao.queryInterNum(3);
        int trainees = studentDao.getTrainee();
        double rate;
        data.put("first",first);
        data.put("second",second);
        data.put("third",third);
        data.put("trainees",trainees);
        if(first == 0){
            data.put("pfirst",0);
        }else{
            rate  = progressDao.queryPassInter(1)/first * 100;
            data.put("pfirst",String.format("%.2f",rate));
        }
        if(second == 0){
            data.put("psecond",0);
        }else{
            rate  = progressDao.queryPassInter(2)/second * 100;
            data.put("psecond",String.format("%.2f",rate));
        }
        if(third == 0){
            data.put("pthird",0);
        }else{
            rate  = progressDao.queryPassInter(3)/second * 100;
            data.put("pthird",String.format("%.2f",rate));
        }
        if(trainees == 0){
            data.put("ptrainee",0);
        }else{
            rate = studentDao.getPassTrai()/trainees *100;
            data.put("ptrainee",String.format("%.2f",rate));
        }
        return data;
    }

    /**
     * 查询面试评价信息
     * @param id
     * @return
     */
    @Override
    public List<Progress> getInterById(int id) {
        return progressDao.getInterById(id);
    }
}
